#!/bin/sh

echo -e  "adc linearity measurement\n"

## check if programms are available
if [ ! -e ./spektrum ]
then
    echo "error: spektrum not found"
    echo "       (must me in the same path as linearity.sh)"
    exit 1
fi

if [ ! -e ./lin ]
then
    echo "error: lin not found"
    echo "       (must me in the same path as linearity.sh)"
    exit 1
fi

if [ ! -e ./bin ]
then
    echo "error: bin not found"
    echo "       (must me in the same path as linearity.sh)"
    exit 1
fi

## check if driver is loaded
if ! lsmod | grep sis1100 >/dev/null
then
    echo "driver not loaded. "

    if [ ! -e ./load_module ]
    then
	echo "error: load_module not found"
	echo "       (must me in the same path as linearity.sh)"
    fi

    echo -n "trying to load driver..."
    ./load_module >/dev/null

    #check if loading driver was successfull
    if ! lsmod |grep sis1100 >/dev/null
    then
	echo -e "errror\n"
	exit 2
    else
	echo -e "ok\n"
    fi
fi

STAMP=`date +%y%m%d_%H%M`
TIME=5
CT=1000

echo STAMP=$STAMP

./spektrum -t $TIME -c $T -s $STAMP
